package innerclassdemo2;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 阿宾
 * Date: 2024-10-16
 * Time: 11:05
 */
public class OutClass{
    public int data1 = 7;
    public int data2 = 29;
    public static int data3 = 89;

    public void test(){
        int a = 2;
        System.out.println("外部类的非静态test方法");
    }
    public static void test1(){
        System.out.println("外部类的静态test方法");
    }
    //静态内部类
    static class InnerClass{
        int a = 10;
        static int b = 20;
        public void test2(){
            System.out.println(data3);//直接访问外部类的静态成员
            test1();//直接访问外部类的静态方法

            //访问外部类的非静态成员或方法
            /*
            1.先创建外部类对象
            2.通过外部类对象访问成员
             */
            OutClass outClass = new OutClass();
            System.out.println(outClass.data1);
            outClass.test();
        }
        public static void test(){
            System.out.println("静态内部类的静态test方法");
        }
    }
}
